package com.hongxun.design.ui.statisticsmap.pieview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hongxun.design.R;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/29.
 */
public class MPiewChartAdapter extends BaseAdapter {
    Context context;
    List<PieItemBean> items;
    LayoutInflater inflater;

    public MPiewChartAdapter(Context context, List<PieItemBean> items) {
        this.context = context;
        this.items = items;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int i) {
        return items.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        PieItemBean bean = (PieItemBean) getItem(i);
        Holldler holldler = null;
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_mpiewchart, null);
            holldler = new Holldler(view);
            view.setTag(holldler);
        } else {
            holldler = (Holldler) view.getTag();
        }

        try {

            holldler.point_pie.setBackgroundColor(bean.getColor());
            holldler.title.setText(bean.getItemType());
            holldler.value.setText(((int)bean.getItemValue()) + "");
        } catch (Exception e) {
        }


        return view;
    }

    class Holldler {
        TextView title, value;
        CircularView point_pie;

        Holldler(View v) {
            point_pie = (CircularView) v.findViewById(R.id.point_pie);
            title = (TextView) v.findViewById(R.id.pie_title);
            value = (TextView) v.findViewById(R.id.pie_value);
        }

    }
}
